package org.hotelsystem.hoteladminsystem.Service.IMP;

import org.hotelsystem.hoteladminsystem.Mapper.HotelMapper;
import org.hotelsystem.hoteladminsystem.Pojo.Hotel;
import org.hotelsystem.hoteladminsystem.Service.HotelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class HotelServiceIMP implements HotelService {

    @Autowired
    private HotelMapper hotelMapper;

    /**
     * 获取所有酒店信息
     *
     * @return Map<String, Object>
     */
    @Override
    public Map<String, Object> getAllHotelsData() {
        Map<String, Object> result = new HashMap<>();
        try {
            List<Hotel> hotels = hotelMapper.selectAllHotels();
            result.put("status", "200");
            result.put("message", "获取成功");
            result.put("count", hotels.size());
            result.put("result", true);
            result.put("data", hotels);

        } catch (Exception e) {
            result.put("status", "500");
            result.put("message", "后台错误");
            result.put("count", 0);
            result.put("result", false);
            result.put("data", null);
        }
        return result;
    }

    /**
     * 根据ID获取酒店信息
     * @return Map<String, Object>
     */
    @Override
    public Map<String, Object> getHotelDataByID(int id) {
        Map<String, Object> result = new HashMap<>();
        try {
            Hotel hotel = hotelMapper.selectHotelById(id);
            result.put("status", "200");
            result.put("message", "获取成功");
            result.put("count", 1);
            result.put("result", true);
            result.put("data", hotel);
        } catch (Exception e) {
            result.put("status", "500");
            result.put("message", "后台错误");
            result.put("count", 0);
            result.put("result", false);
            result.put("data", null);
        }
        return result;
    }


}
